<?php

namespace Biz\model\trade;

use Medoo\Medoo;

class OrderExcel extends \Doraemon\pockets\datebase\BaseDbModel
{
    const _CONFIG_FILE_ = 'db_shop';

    const _CONFIG_SELECT_ = 'db_trade';

    const _DATABASE_ = 'shop_trade';

    const _TABLE_NAME = 'order_excel';


    const ORDER_BATCH_EXCEL_FALSE = 0;//批量发货操作中
    const ORDER_BATCH_EXCEL_SUCCESS = 1;//批量发货操作完成


    public static function create($isSuccess, $shopId, $message)
    {
        self::insert([
            'is_success' => $isSuccess,
            'shop_id'    => $shopId,
            'message'    => $message,
            'addtime'    => date('Y-m-d H:i:s')
        ]);
        return self::id();
    }

    public static function getOrderExcelInfoByIdFromMaster($id)
    {

        $info = self::select_master("*", Medoo::raw(' where id=:id for update', [':id' => $id]));

        $info = array_shift($info);

        if (empty($info)) {
            return false;
        }

        return $info;
    }

    public static function getInfoById($id)
    {
        $info= self::get('*',['id'=>$id]);

        if(empty($info)){
            return (object)[];
        }
        return $info;
    }

    public static function updateData($field, $where)
    {
        $ret = self::update($field, $where);
        if ($row = $ret->rowCount() > 0) {
            return $row;
        }
        return false;
    }

    public static function getList($where)
    {
        $list=self::select('*',$where);

        if(empty($list)){
            return [];
        }
        return $list;
    }

}